package servlet;

import java.io.IOException;
import java.net.URL;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gdata.client.photos.PicasawebService;
import com.google.gdata.data.photos.AlbumFeed;
import com.google.gdata.data.photos.GphotoEntry;
import com.google.gdata.data.photos.PhotoEntry;
import com.google.gdata.util.ServiceException;

public class test extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		super.doGet(req, resp);		
		
		try {
			int i=0;
			
			String strAcc = "thyp1213";
			String strPwd = "MasterHypermedia";

			PicasawebService service = new PicasawebService("sample");
			service.setUserCredentials(strAcc, strPwd);
			
			URL feedUrl = new URL("https://picasaweb.google.com/data/feed/api/user/" + strAcc + "?kind=album");
			
			AlbumFeed myUserFeed = service.getFeed(feedUrl, AlbumFeed.class);
			List<GphotoEntry> lAlbum = myUserFeed.getEntries();		
			for (GphotoEntry myAlbum : lAlbum) {
				String albumID = myAlbum.getGphotoId();
				System.out.println(myAlbum.getTitle().getPlainText());
				System.out.println(albumID);
				
				URL feedPhotoUrl = new URL("https://picasaweb.google.com/data/feed/api/user/"+strAcc+"/albumid/"+albumID);
				AlbumFeed feed = service.getFeed(feedPhotoUrl, AlbumFeed.class);
				
				for(PhotoEntry photo : feed.getPhotoEntries()) {
				    System.out.println(photo.getTitle().getPlainText());
				    i++;
				}
			}			
			
			System.out.println(i);

		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}